package com.wego.service.impl;

import com.wego.common.base.impl.BaseServiceImpl;
import com.wego.entity.domain.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wego.mapper.CategoryMapper;
import com.wego.service.CategoryService;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @className: CategoryServiceImpl
 * @description: TODO 类描述 
 * @author: Kuangkeli
 * @date: 2023/07/10 17:03
 **/

@Service
public class CategoryServiceImpl extends BaseServiceImpl<Category> implements CategoryService{

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public List<Category> selectAll() {
        return categoryMapper.selectList(null);
    }

    @Override
    public List<Category> selectCategoryByPid(Long pid) {
        final Example example = new Example(Category.class);
        final Example.Criteria criteria = example.createCriteria();
        if (pid == null) {
            criteria.andIsNull("pid");
        } else {
            criteria.andEqualTo("pid", pid);
        }
        return categoryMapper.selectByExample(example);
    }


    @Override
    public Long getCounts() {
        return categoryMapper.getCounts();
    }

}
